package com.ruoyi.warehouse.service.impl;

import java.util.List;

import com.ruoyi.stock.mapper.MStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.warehouse.mapper.MWarehouseMapper;
import com.ruoyi.warehouse.domain.MWarehouse;
import com.ruoyi.warehouse.service.IMWarehouseService;

/**
 * 仓库表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@Service
public class MWarehouseServiceImpl implements IMWarehouseService 
{
    @Autowired
    private MWarehouseMapper mWarehouseMapper;

    @Autowired
    private MStockMapper mStockMapper;

    /**
     * 查询仓库表
     * 
     * @param warehouseId 仓库表主键
     * @return 仓库表
     */
    @Override
    public MWarehouse selectMWarehouseByWarehouseId(Long warehouseId)
    {
        return mWarehouseMapper.selectMWarehouseByWarehouseId(warehouseId);
    }

    /**
     * 查询仓库表列表
     * 
     * @param mWarehouse 仓库表
     * @return 仓库表
     */
    @Override
    public List<MWarehouse> selectMWarehouseList(MWarehouse mWarehouse)
    {
        return mWarehouseMapper.selectMWarehouseList(mWarehouse);
    }

    /**
     * 新增仓库表
     * 
     * @param mWarehouse 仓库表
     * @return 结果
     */
    @Override
    public int insertMWarehouse(MWarehouse mWarehouse)
    {
        return mWarehouseMapper.insertMWarehouse(mWarehouse);
    }

    /**
     * 修改仓库表
     * 
     * @param mWarehouse 仓库表
     * @return 结果
     */
    @Override
    public int updateMWarehouse(MWarehouse mWarehouse)
    {
        return mWarehouseMapper.updateMWarehouse(mWarehouse);
    }

    /**
     * 批量删除仓库表
     * 
     * @param warehouseIds 需要删除的仓库表主键
     * @return 结果
     */
    @Override
    public int deleteMWarehouseByWarehouseIds(Long[] warehouseIds)
    {
        // 判断是否有库存
        if(mStockMapper.checkStockByWarehouseIds(warehouseIds)!=0){
            return 0;
        }
        return mWarehouseMapper.deleteMWarehouseByWarehouseIds(warehouseIds);
    }

    /**
     * 删除仓库表信息
     * 
     * @param warehouseId 仓库表主键
     * @return 结果
     */
    @Override
    public int deleteMWarehouseByWarehouseId(Long warehouseId)
    {
        return mWarehouseMapper.deleteMWarehouseByWarehouseId(warehouseId);
    }
}
